<!-- 添加设备 - 绘制分区 -->
<template>
  <div>
    <el-dialog :visible.sync="dialogVisibleEquipment" :before-close="handleCloseBindWarnStandardEquipment" :close-on-click-modal="false" :title="title" width="935px" height="300px">
      <el-form v-loading="formLoading" ref="dialogFormEquipment" :model="dialogFormEquipment" :rules="rules" label-width="120px" class="twoColumn">
        <el-form-item label="所属单位" prop="name">
          <el-input v-model="subordinateUnit" class="el-disabled" readonly="readonly"/>
        </el-form-item>
        <el-form-item label="所属建筑群1" prop="park_name">
          <el-input v-model="dialogFormEquipment.park_name" class="el-disabled" readonly="readonly"/>
        </el-form-item>
        <el-form-item label="所属建筑" prop="build_name">
          <el-input v-model="dialogFormEquipment.build_name" class="el-disabled" readonly="readonly"/>
        </el-form-item>
        <el-form-item label="所属楼层" prop="floor_name">
          <el-input v-model="dialogFormEquipment.floor_name" class="el-disabled" readonly="readonly"/>
        </el-form-item>
        <el-form-item label="所属分区" prop="partition_name">
          <el-select v-model="dialogFormEquipment.partition_name" class="filter-item" placeholder="请选择所属分区">
            <el-option v-for="(key, value) in statusMap" :key="key" :label="key" :value="value" />
          </el-select>
        </el-form-item>
        <el-form-item label="位置" prop="position">
          <el-input v-model="dialogFormEquipment.position" placeholder="请输入位置" autocomplete="off"/>
        </el-form-item>
        <el-form-item label="设备系统" prop="equipment_name">
          <el-select v-model="dialogFormEquipment.equipment_name" class="filter-item" placeholder="请选择设备系统">
            <el-option v-for="(key, value) in systemList" :key="key" :label="key" :value="value" />
          </el-select>
        </el-form-item>
        <el-form-item label="设备类型" prop="equipment_type">
          <el-select v-model="dialogFormEquipment.equipment_type" class="filter-item" placeholder="请选择设备类型">
            <el-option v-for="(key, value) in deviceTypeList" :key="key" :label="key" :value="value" />
          </el-select>
        </el-form-item>
        <el-form-item label="设备模型" prop="equipment_modal">
          <el-select v-model="dialogFormEquipment.equipment_modal" class="filter-item" placeholder="请选择设备模型">
            <el-option v-for="(key, value) in deviceModelList" :key="key" :label="key" :value="value" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormEquipment">确 定</el-button>
        <el-button @click="handleCancelEquipment">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { systemList, deviceTypeList, deviceModelList } from '@/api/common'
const statusMap = {
  10: '单位10',
  12: '单位12',
  20: '单位20',
  30: '单位30',
  40: '单位40',
  50: '单位50',
  60: '单位60',
  70: '单位70',
  80: '单位80',
  90: '单位90'
}
export default {
  props: {
    dialogVisibleEquipment: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    dialogFormEquipment: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      title: '',
      subordinateUnit: '奉贤区万顺路2277弄南行贤苑',
      statusMap,
      equipmentSystem: this.GLOBAL.equipmentSystem,
      // 添加form验证
      rules: {
        building_name: [{
          required: true,
          message: '请输入建筑名称',
          trigger: 'change'
        }],
        architectural_age: [{
          required: true,
          message: '请选择建筑年代',
          trigger: 'change'
        }],
        acceptance_date: [{
          required: true,
          message: '请选择验收日期',
          trigger: 'change'
        }],
        latitude: [{
          required: true,
          message: '请选择所在经纬度',
          trigger: 'change'
        }]
      },
      systemList: [],
      deviceTypeList: [],
      deviceModelList: [],
      formLoading: false
    }
  },
  computed: {
  },
  created() {
    this.title = '添加设备'
    this.$nextTick(function() {
      this.getSystem()
      this.getDeviceType()
      this.getDeviceModel()
    })
  },
  methods: {
    submitFormEquipment(val) {
      this.$refs['dialogFormEquipment'].validate((valid) => {
        if (valid) {
          const that = this
          that.$message.success('添加成功！')
          that.$emit('submitFormEquipment', this.dialogFormEquipment)
        }
      })
    },
    // 关闭弹窗
    handleCancelEquipment() {
      this.$emit('getCancelEquipment')
    },
    // 关闭弹窗，不可以删这个方法。不用这个方法点击遮罩层关闭会报错
    handleCloseBindWarnStandardEquipment() {
      this.$emit('closeBindWarnStandardEquipment')
    },
    // 获取设备系统
    getSystem() {
      const that = this
      systemList()
        .then(response => {
          const data = response.data
          that.formLoading = false
          this.dialogVisible = false
          if (data.code === 40000) {
            that.systemList = data.data
          } else {
            that.$message.warning(data.message)
          }
        })
        .catch((err) => {
          console.log(err)
          that.formLoading = false
        })
    },
    // 获取设备类型
    getDeviceType() {
      const that = this
      deviceTypeList()
        .then(response => {
          const data = response.data
          that.formLoading = false
          this.dialogVisible = false
          if (data.code === 40000) {
            that.deviceTypeList = data.data
          } else {
            that.$message.warning(data.message)
          }
        })
        .catch((err) => {
          console.log(err)
          that.formLoading = false
        })
    },
    // 获取设备模型
    getDeviceModel() {
      const that = this
      deviceModelList()
        .then(response => {
          const data = response.data
          that.formLoading = false
          this.dialogVisible = false
          if (data.code === 40000) {
            that.deviceModelList = data.data
          } else {
            that.$message.warning(data.message)
          }
        })
        .catch((err) => {
          console.log(err)
          that.formLoading = false
        })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.img-column{
  width: 50%;
  height: 118px;
  float: left;
  .el-form-item{
    width: 100%;
    float: left;
  }
}
.img-tips{
	font-size: 13px;
	font-weight: 900;
	color: #D13E3E;
}
.img-form-item{
  margin-bottom: 0px;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 104px;
  height: 104px;
  line-height: 104px;
  text-align: center;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader-icon:hover{
  border-color: #409EFF;
}
.avatar {
  width: 104px;
  height: 104px;
  display: block;
}
// 地区、地址
.regionAddCombination{
  .el-cascader{
    width: 160px;
  }
  .el-input{
    width: 136px;
  }
}
// 经纬度
.mapInfo{
  position:relative;
  .el-input{
    width: 136px;
  }
  i{
    position: absolute;
    right: 0;
    top: 0;
    display: block;
    width: 30px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    font-size: 20px;
    cursor: pointer;
    -webkit-appearance: none;
    background-color: #FFF;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #DCDFE6;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    outline: 0;
    -webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
  }
  i:hover{
    border-color: #C0C4CC;
  }
}
.mapInfo-map{
  .el-input{
    width: 49.5%;
  }
}
#map{
  width:100%;
  height: 300px;
}
.amap-demo{
  height: 300px;
}
</style>
